﻿using CTP.CRM.Core.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CTP.CRM.Repository
{
    /// <summary>
    /// 仓储基类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class BasicRepository<T> : SimpleClient<T> where T : class, new()
    {
        public BasicRepository(SqlSugarScope context = null) : base(context)
        {
            Context = SqlsugarScopeBasic.GetContextSafely("default");
        }

        public async Task<bool> UpdateAsync(Expression<Func<T, object>> columns, List<T> updateObj)
        {
            return (await SqlsugarScopeBasic.GetContextSafely("default").Updateable(updateObj).UpdateColumns(columns).ExecuteCommandAsync()) > 0;
        }
    }

    public class BiCenterRepository<T> : SimpleClient<T> where T : class, new()
    {
        public BiCenterRepository(SqlSugarScope context = null) : base(context)
        {
            Context = SqlsugarScopeBasic.GetContextSafely("CTPbicenter");
        }
    }

    public class BiStarRocksRepository<T> : SimpleClient<T> where T : class, new()
    {
        public BiStarRocksRepository(SqlSugarScope context = null) : base(context)
        {
            Context = SqlsugarScopeBasic.GetContextSafely("starrocks");
        }
    }
}
